//
//  LotteryDetailViewController.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/18.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "LotteryDetailViewController.h"
#import "LotteryListCell.h"
#import "LotteryModel.h"
#import "LotteryPrizeModel.h"
#import "moneyCell.h"

@interface LotteryDetailViewController ()
<
    UITableViewDelegate,
    UITableViewDataSource
>

@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) UIView * tempView;
@end

@implementation LotteryDetailViewController


-(UITableView *) tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, DEF_DEVICE_WIDTH, DEF_CONTENT_INTABBAR_HEIGHT) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        
        [MXUtility setExtraCellLineHidde:_tableView tabHeader:YES tabFooter:NO];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationItem setTitle:@"历史开奖"];

    [self.view addSubview:self.tableView];
    
    [self createTempView];
    
    if ([self.prizeModelArrayList count] == 0) {
        [self.tempView setHidden:NO];
    }else{
        [self.tempView setHidden:YES];
    }
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (section == 0) {
        
        return 1;
        
    }else{
        
        return self.prizeModelArrayList.count;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    if (section == 1) {
        
        return 140;
    }else{
        
        return 0;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        
        return 108;
    }else{
        
        return 46;
        
    }
}


-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 100);
    view.backgroundColor = [UIColor whiteColor];
    
    UIView *line = [[UIView alloc]init];
    line.frame = CGRectMake(0, 0, 1, 70);
    
    line.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 50);
    
    [view addSubview: line];
    
    UILabel *sell = [[UILabel alloc]init];
    
    sell.frame = CGRectMake(0, 10, [UIScreen mainScreen].bounds.size.width/2-1, 35);
    
    sell.text = @"本期销量(元)";
    
    [sell setFont:[UIFont systemFontOfSize:15.f]];
    
    sell.textAlignment = 1;
    
    [view addSubview:sell];
    
    UILabel *sellM = [[UILabel alloc]init];
    
    sellM.frame = CGRectMake(0, CGRectGetMaxY(sell.frame)+10, [UIScreen mainScreen].bounds.size.width/2-1, 35);
    
    if ([self.listModel.listsaleamount integerValue] == 0 || [self.listModel.listsaleamount isEqualToString:@""]) {
        sellM.text = @"0";
    }else{
        sellM.text = self.listModel.listsaleamount;
    }
    sellM.textColor = [UIColor redColor];
    
    sellM.font = [UIFont boldSystemFontOfSize:18];
    
    sellM.textAlignment = 1;
    
    [view addSubview:sellM];
    
    UILabel *total = [[UILabel alloc]init];
    total.frame = CGRectMake(CGRectGetMaxX(line.frame), 10, [UIScreen mainScreen].bounds.size.width/2-1, 35);
    
    total.text = @"奖池滚存(元)";
    
    total.textAlignment = 1;
    
    [total setFont:[UIFont systemFontOfSize:15.f]];

    [view addSubview:total];
    
    UILabel *totalM = [[UILabel alloc]init];
    
    totalM .frame = CGRectMake(CGRectGetMaxX(line.frame), CGRectGetMaxY(total.frame)+10, [UIScreen mainScreen].bounds.size.width/2-1, 35);
    
    if ([self.listModel.listtotalmoney integerValue] == 0 || [self.listModel.listtotalmoney isEqualToString:@""] || self.listModel.listtotalmoney == nil ||[self.listModel.listtotalmoney isEqual:[NSNull null]]) {
        totalM.text = @"0";
    }else{
        totalM .text = self.listModel.listtotalmoney;
    }
    totalM .textColor = [UIColor redColor];
    
    totalM .font = [UIFont boldSystemFontOfSize:18];
    
    totalM .textAlignment = 1;
    
    [view addSubview:totalM ];
    
    UIView *huiV = [[UIView alloc]init];
    huiV.frame = CGRectMake(0, CGRectGetMaxY(sellM.frame), [UIScreen mainScreen].bounds.size.width, 40);
    
    [view addSubview:huiV];
    
    UILabel *lev = [[UILabel alloc]init];
    lev.frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width/3 , 40);
    lev.textAlignment = 1;
    lev.text = @"奖项";
    [lev setFont:[UIFont systemFontOfSize:16.f]];

    
    [huiV addSubview:lev];
    
    UILabel *money = [[UILabel alloc]init];
    money.frame = CGRectMake(CGRectGetMaxX(lev.frame), 0,[UIScreen mainScreen].bounds.size.width/3 , 40);
    money.textAlignment = 1;
    money.text = @"每注奖金";
    [money setFont:[UIFont systemFontOfSize:16.f]];

    
    [huiV addSubview:money];
    
    UILabel *num = [[UILabel alloc]init];
    num.frame = CGRectMake(CGRectGetMaxX(money.frame), 0,[UIScreen mainScreen].bounds.size.width/3 , 40);
    num.textAlignment = 1;
    num.text = @"中奖注数";
    [num setFont:[UIFont systemFontOfSize:16.f]];

    
    [huiV addSubview:num];
    
    return view;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        
        static NSString * str = @"cell";
        LotteryListCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"LotteryListCell" owner:self options:nil] lastObject];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        }
        [cell setlotteryListDataSource:self.listModel typeName:self.cpName typeImg:self.cpImg];
        return cell;
        
    }else{
        
        static NSString * str = @"moneyCell";
        moneyCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
        
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"moneyCell" owner:self options:nil] lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setSmallModel:self.prizeModelArrayList[indexPath.row]];
        
        return cell;

    }
    return nil;
}

-(void)createTempView{
    
    self.tempView = [[UIView alloc]initWithFrame:CGRectMake(0, 64,self.view.width, self.view.height)];
    
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake((CGRectGetWidth(self.tempView.frame) - 50)/2, (CGRectGetHeight(self.tempView.frame) - 154)/2, 50, 50)];
    imageview.image = [UIImage imageNamed:@"wushuju"];
    imageview.contentMode = UIViewContentModeScaleAspectFit;
    [self.tempView addSubview:imageview];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0,imageview.height+10 + imageview.y, CGRectGetWidth(self.tempView.frame), 30)];
    label.textColor = DEF_COLOR_RGB(215, 215, 215);
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:15.f];
    label.text = @"暂无数据";
    [self.tempView addSubview:label];
    
    [self.tableView addSubview:self.tempView];
    self.tempView.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
